package com.mchina.myMaven.rest.service.imp;


import com.mchina.myMaven.rest.dao.BaseDao;
import com.mchina.myMaven.rest.service.BaseService;
import net.nelz.simplesm.annotations.ReadThroughAssignCache;
import net.nelz.simplesm.annotations.ReadThroughSingleCache;
import net.nelz.simplesm.annotations.UpdateSingleCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-5-17
 * Time: 14:32:35
 */
@Transactional
public class BaseServiceImp<T extends Serializable> implements BaseService<T> {
    protected Logger log = LoggerFactory.getLogger(getClass());
    private BaseDao<T> dao;

    public BaseDao<T> getDao() {
        return dao;
    }

    public void setDao(BaseDao<T> dao) {
        this.dao = dao;
    }

    @Transactional(readOnly = true)
    @ReadThroughSingleCache(namespace = "load", expiration = 3600)
    public T findById(Serializable id) {
        return dao.get(id);
    }


    @Override
    @ReadThroughSingleCache( namespace = "load", expiration = 3600)
    public T load(Serializable id) {
        return dao.load(id);
    }

    @Override
    /*@ReadThroughAssignCache(namespace = "_user_test_", expiration = 3600,assignedKey = "all")*/
    public List<T> findAll( ) {
        return dao.findAll();
    }

    @Override
    public List findByEgListByNamedQueryAndNamedParam(T eg, String orderName, int orderType, int firstResult, int maxResult, String[] paramNames, Object[] values) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List findByEgList(T eg, String orderName, int orderType, int firstResult, int maxResults, String property, Object value) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override

    public int doSql(String sql) {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }


    @Override
    public Object updateDefault(Object entity) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public T save(T entity) {
        return dao.save(entity);
    }

    @Override
    @UpdateSingleCache(expiration = 3600)
    public Object update(Object o) {
        return dao.update(o);
    }

    @Override
    public Object saveOrUpdate(Object o) {
        return dao.saveOrUpdate(o);
    }

    @Override
    public void delete(Object o) {
        dao.delete(o);
    }

    @Override
    public T deleteById(Serializable id) {
        return dao.deleteById(id);
    }

    @Override
    public List<T> deleteById(Serializable[] ids) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }


    public List<T> findByProperty(String property, Object value) {
        return dao.findByProperty(property, value);
    }

    public int countByProperty(String[] property, Object[] value) {
        return dao.countByProperty(property, value);
    }


}


